<?php

/**
 *  @FileComment            [货品列表修改模型]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：GoodsListEditModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-14 2:12:50
 *  *
 */
class GoodsListEditModel extends Model {

        public $table = 'goods_list';
        public $validate = array(
            array('stock', 'nonull', '库存不能为空', 2, 3),
            array('number', 'nonull', '货号不能为空', 2, 3),
            array('number', '_distinct', '货品编号不能重复', 2, 3)
        );

        public function _distinct($name, $value, $msg, $arg) {
                $glid = Q('post.glid', 0, 'intval');
                $data = $this->where('number=' . $value . ' and glid!=' . $glid)->find();
                if ($data) {
                        return $msg;
                } else {
                        return true;
                }
        }

        public function update_data($glid) {
                return $this->where(array('glid' => $glid))->update();
        }

}
